<template>
	<u-tabbar v-model="current" :list="list" :before-switch="beforeSwitch" icon-size="50" 
	:_autoFun="autoFun" :mid-button="mid" :mid-button-size="60" height="110" active-color="#000"></u-tabbar>
</template>

<script>
	export default {
		name: "tabbar",
		props: {
			_current:{
				type: Number,
				default:0
			},
			getCartNum:{
				type: Number,
				default:0
			}
		},
		data() {
			return {
				baseUrl: this.config.baseUrl,
				list:[],
				current:this._current,
				mid:false
			}
		},
		computed:{
			autoFun(){
				if (this.getCartNum == 1){
					this.loadCartNum();
				}
			}
		},
		created() {
			this.getTarbar()
		},
		methods: {
			beforeSwitch(index){
				// this.app.goPage(this.list[index].url);
				this.navTo(this.list[index].url)
				return false;
			},
			getTarbar(){
				this.$u.get('shop/api.index/tarbar').then(res => {
					if(res.data.length > 0){
						this.list = []
						
						res.data.forEach(item => {
							this.list.push({
								iconPath: this.baseUrl+item.imgurl,
								selectedIconPath: this.baseUrl+item.select_imgurl,
								text: item.title,
								isDot: false,
								customIcon: false,
								midButton: item.is_mid ? true : false,
								url:item.data
							})
							if(item.is_mid){
								this.mid = true
							}
						})
					}else{
						this.list = [{
								iconPath: "home",
								selectedIconPath: "home-fill",
								text: '首页',
								isDot: false,
								customIcon: false,
								url:'/pages/shop/index/index'
							},
							{
								iconPath: "bag",
								selectedIconPath: "bag-fill",
								text: '商品',
								customIcon: false,
								url:'/pages/shop/goods/index'
							},
							{
								iconPath: "shopping-cart",
								selectedIconPath: "shopping-cart-fill",
								text: '购物车',
								count: 0,
								midButton: true,
								customIcon: false,
								url:'/pages/shop/flow/cart'
							},
							{
								iconPath: "share",
								selectedIconPath: "share-fill",
								text: '分享',
								isDot: false,
								customIcon: false,
								url:'/pages/member/center/myCode'
							},
							{
								iconPath: "account",
								selectedIconPath: "account-fill",
								text: '我的',
								isDot: false,
								customIcon: false,
								url:'/pages/member/center/index'
							},
						]
					}
				})
			},
			//加载购物车中商品数
			async loadCartNum() {
				this.$u.post('shop/api.flow/getCartInfo').then(res => {
					let cartNum = res.data.num;
					this.$set(this.list[2], 'count', cartNum);
				})
			},
		}
	}
</script>
<style>
</style>
